/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-09 18:59:41
 * @LastEditTime: 2019-08-26 20:55:04
 * @LastEditors: Please set LastEditors
 */
window.onload = function () {
  var btn = document.getElementById('btn');
  var btn2 = document.getElementById('btn2');
  //查数据
  ajax({
    url: "http://10.36.149.48/wbiao/interface/showlist.php",
    success: function(data) {
      console.log("-data-" + data);
      var t = data;
      if (t.indexOf("连接失败") > 0) {
        console.log("===");
        //建表
        ajax({
          url:
            "http://10.36.149.48/wbiao/interface/model/create_wbdatabase.php",
          success: function(data) {
            console.log(data); //拿到返回的数据
          }
        });
        //建表
        ajax({
          url:
            "http://10.36.149.48/wbiao/interface/model/create_wbtable.php",
          success: function(data) {
            console.log(data); //拿到返回的数据
          }
        });
      }
    }
  });

  btn.onclick = function () { 
    console.log('添加数据')
    ajax({
      url: "http://10.36.149.48/wbiao/interface/addwb.php",
      data: {
        // VALUES ('$id','$title','$detail','$name','$img','$caizhi','$price','$remark')";
        id: "3",
        title: "title",
        detail: "detail",
        name: "name",
        img: "img",
        caizhi: "caizhi",
        num: "2",
        price: "price",
        remark: ""
      },
      success: function(data) {
        console.log("==添加数据=" + data); //拿到返回的数据
      }
    });
    
  }

  btn2.onclick = function() {
    ajax({
      url: "http://10.36.149.48/wbiao/interface/delwb.php",
      data: {
        id: '44'
      },
      success: function(data) {
        console.log("===" + data); //拿到返回的数据
      }
    });
  };
  btn3.onclick = function() {
    ajax({
      url: "http://10.36.149.48/wbiao/interface/changewb.php",
      data: {
        id: '3',
        num: '50'
      },
      success: function(data) {
        console.log("===" + data); //拿到返回的数据
      }
    });
  };
};
